<template>
  <el-container>
    <el-header>
      <div>   <img src="@/assets/images/014.jpg" alt="">
        屎蛋哥哥 </div>
      <div>公司后台管理系统</div>
      <div>
        <el-button type="info" @click="loginOut">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px':'200px'">
        <div class="toggleBtn" @click="toggle">|||</div>
     
        <el-menu
          :collapse="isCollapse"
          :collapse-transition="false"
          default-active="2"
          :unique-opened="true"
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#ffd04b"
          :router="true"
        >
          <el-submenu :index="item.id+''" v-for="item in MenusList" :key="item.id">
            <template slot="title">
              <i class="el-icon-user-solid"></i>
              <span>{{ item.authName }}</span>
            </template>
           
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
               <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
            </el-menu-item>
          </el-submenu>

         
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <!-- 二级路由 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {getLeftMenusAPI} from '@/http/api'
export default {
  name: "Home",
  data() {
    return {
      isCollapse:false,
      //左侧菜单列表
      MenusList:[],
    }
  },
  //组件实例创建后，通常用于组件加载立马获取后台数据
  created() {
    //拉取左侧菜单权限列表
    this.getLeftMenus()
  },
  methods: {
    //退出登录
    loginOut() {
      sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
    toggle() {
      this.isCollapse=!this.isCollapse;
    },
    async getLeftMenus() {
      //调左侧菜单权限接口
      const res=await getLeftMenusAPI()
       console.log('调左侧菜单权限接口',res)
       this.MenusList=res;
    }
  },
};
</script>

<style lang="scss" scoped>
.el-container {
  height: 100%;
}
.el-header {
  background: #373d41;
  color: #fff;
  display: flex;
  & > div {
    flex: 3;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  & > div:nth-child(1) {
    flex: 1;
  
    color: #CCC;
    img{
         width: 50px;
        height: 50px;
        border-radius: 50%;

    }
  }

  & > div:nth-child(2) {
    flex: 3;
  }

  & > div:nth-child(3) {
    flex: 1;
  }
}

.el-aside {
  background: #333744;
  // height: 100vh;  //vw,vh
}

.toggleBtn {
  color: #ccc;
  text-align: center;
  line-height: 30px;
  background:#333;
  width:100%;
  cursor: pointer;
}

.el-menu {
  border-right:none;
}

.el-main {
  background: #eaedf1;
}
</style>

